﻿namespace mVids
{
    using MediaPortal.Configuration;
    using MediaPortal.Profile;
    using MediaPortal.ServiceImplementations;
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;

    public class thumbDlg : Form
    {
        private Button button1;
        private Button button2;
        private IContainer components = null;
        private string ffmpegpath;
        private Label label1;
        private Label label2;
        private PictureBox pictureBox1;
        private string songPath;
        private TextBox textBox1;
        private string thumbdir = Config.GetFolder(Config.Dir.Thumbs);

        public thumbDlg(string imgFilename, string path)
        {
            this.InitializeComponent();
            Settings settings = new Settings(Config.GetFolder(Config.Dir.Config) + "/MediaPortal.xml", false);
            this.textBox1.Text = settings.GetValue("mvid", "thumbtime");
            this.ffmpegpath = settings.GetValue("mvid", "ffmpeg");
            this.pictureBox1.ImageLocation = imgFilename;
            this.songPath = path;
            settings.Dispose();
            Log.Debug("THUMBS " + this.songPath.Remove(0, this.songPath.LastIndexOf(@"\") + 1) + ".jpg", new object[0]);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Process process = new Process {
                StartInfo = { Arguments = " -i \"" + this.songPath + "\" -s 324*182 -ss " + this.textBox1.Text + " -vframes 1 -f image2 -vcodec mjpeg \"" + this.thumbdir + @"\mvids\Videos\" + this.songPath.Remove(0, this.songPath.LastIndexOf(@"\") + 1) + ".jpg\"", WindowStyle = ProcessWindowStyle.Hidden, FileName = this.ffmpegpath }
            };
            process.Start();
            process.WaitForExit();
            this.pictureBox1.ImageLocation = this.thumbdir + @"\mvids\Videos\" + this.songPath.Remove(0, this.songPath.LastIndexOf(@"\") + 1) + ".jpg";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.pictureBox1 = new PictureBox();
            this.textBox1 = new TextBox();
            this.label1 = new Label();
            this.label2 = new Label();
            this.button1 = new Button();
            this.button2 = new Button();
            ((ISupportInitialize) this.pictureBox1).BeginInit();
            base.SuspendLayout();
            this.pictureBox1.BorderStyle = BorderStyle.FixedSingle;
            this.pictureBox1.Location = new Point(12, 12);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new Size(0x144, 0xb6);
            this.pictureBox1.TabIndex = 0;
            this.pictureBox1.TabStop = false;
            this.textBox1.Location = new Point(0x184, 9);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new Size(0x22, 20);
            this.textBox1.TabIndex = 1;
            this.textBox1.TextAlign = HorizontalAlignment.Right;
            this.label1.AutoSize = true;
            this.label1.Location = new Point(0x153, 12);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x34, 13);
            this.label1.TabIndex = 2;
            this.label1.Text = "Positition:";
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0x1a8, 12);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x23, 13);
            this.label2.TabIndex = 3;
            this.label2.Text = "(secs)";
            this.button1.Location = new Point(0x16e, 0x2e);
            this.button1.Name = "button1";
            this.button1.Size = new Size(0x4b, 0x17);
            this.button1.TabIndex = 4;
            this.button1.Text = "Preview";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new EventHandler(this.button1_Click);
            this.button2.Location = new Point(0x160, 0x9a);
            this.button2.Name = "button2";
            this.button2.Size = new Size(0x63, 40);
            this.button2.TabIndex = 5;
            this.button2.Text = "Done";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new EventHandler(this.button2_Click);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1ce, 0xd3);
            base.Controls.Add(this.button2);
            base.Controls.Add(this.button1);
            base.Controls.Add(this.label2);
            base.Controls.Add(this.label1);
            base.Controls.Add(this.textBox1);
            base.Controls.Add(this.pictureBox1);
            base.Name = "thumbDlg";
            this.Text = "Thumb Generator";
            ((ISupportInitialize) this.pictureBox1).EndInit();
            base.ResumeLayout(false);
            base.PerformLayout();
        }
    }
}

